package lowijs.XfireClient.packet;

import lowijs.XfireClient.*;

public class LoginPacket extends Packet {
	private final byte[] p_login_1 = new byte[] {
			0x01, 0, 0x03, 0x04,
			0x6E, 0x61, 0x6D, 0x65, // 'name'
	};
	
	private final byte[] p_login_2 = new byte[] {
			0x08,
			0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64, // 'password'
			0x01, 0x28, 0
	};
	
	private final byte[] p_login_3 = new byte[] {
			0x05,
			0x66, 0x6C, 0x61, 0x67, 0x73, // 'flags'
			0x02, 0, 0, 0, 0, 0x03,
			0x73, 0x69, 0x64, // 'sid'
			0x03, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	};
	
	public LoginPacket(String u, String p, String s) {
		String hash = Util.toSHA1(Util.toSHA1(u + p + "UltimateArena") + s);
		
		putBytes(p_login_1);
		
		// username
		putString(u);
		
		// password
		putBytes(p_login_2);
		putBytes(hash.getBytes());
		
		// flags
		putBytes(p_login_3);
	}
}
